package com.ai.wx.entity;

// Generated 2015-5-18 15:07:11 by Hibernate Tools 4.0.0

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;

import com.ai.core.cache.AICacheManager;
import com.ai.core.constant.GlobalConstant;
import com.ai.core.util.Arith;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * AgentBrokerageDtl generated by hbm2java
 */
@Entity
@Table(name = "agent_brokerage_dtl", catalog = "wx")
public class AgentBrokerageDtl implements java.io.Serializable {

	private Integer id;
	private Integer agentId;
	private Integer brokerageId;
	private Integer orderId;
	private String productId;
	private Integer productTariff;
	private Integer rate;
	private Integer charge;
	private Integer state;
	private Date crtDate;
	private Date modDate;
	private String crtUid;
	private String modUid;

	public AgentBrokerageDtl() {
	}

	public AgentBrokerageDtl(Integer agentId, Integer brokerageId, Integer orderId, String productId, Integer productTariff, Integer rate, Integer charge, Integer state, Date crtDate, Date modDate, String crtUid, String modUid) {
		this.agentId = agentId;
		this.brokerageId = brokerageId;
		this.orderId = orderId;
		this.productId = productId;
		this.productTariff = productTariff;
		this.rate = rate;
		this.charge = charge;
		this.state = state;
		this.crtDate = crtDate;
		this.modDate = modDate;
		this.crtUid = crtUid;
		this.modUid = modUid;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "Id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "agent_id")
	public Integer getAgentId() {
		return this.agentId;
	}

	public void setAgentId(Integer agentId) {
		this.agentId = agentId;
	}

	@Column(name = "brokerage_id")
	public Integer getBrokerageId() {
		return this.brokerageId;
	}

	public void setBrokerageId(Integer brokerageId) {
		this.brokerageId = brokerageId;
	}

	@Column(name = "order_id")
	public Integer getOrderId() {
		return this.orderId;
	}

	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	@Column(name = "product_id", length = 50)
	public String getProductId() {
		return this.productId;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	@Column(name = "product_tariff")
	public Integer getProductTariff() {
		return this.productTariff;
	}

	public void setProductTariff(Integer productTariff) {
		this.productTariff = productTariff;
	}

	@Column(name = "rate")
	public Integer getRate() {
		return this.rate;
	}

	public void setRate(Integer rate) {
		this.rate = rate;
	}

	@Column(name = "charge")
	public Integer getCharge() {
		return this.charge;
	}

	@Transient
	public double getDCharge() {
		return Arith.div100(charge);   
	}
	
	public void setCharge(Integer charge) {
		this.charge = charge;
	}

	@Column(name = "state")
	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}


	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "crt_date", length = 0)
	public Date getCrtDate() {
		return this.crtDate;
	}

	public void setCrtDate(Date crtDate) {
		this.crtDate = crtDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "mod_date", length = 0)
	public Date getModDate() {
		return this.modDate;
	}

	public void setModDate(Date modDate) {
		this.modDate = modDate;
	}

	@Column(name = "crt_uid")
	public String getCrtUid() {
		return this.crtUid;
	}

	public void setCrtUid(String crtUid) {
		this.crtUid = crtUid;
	}

	@Column(name = "mod_uid")
	public String getModUid() {
		return this.modUid;
	}

	public void setModUid(String modUid) {
		this.modUid = modUid;
	} 
	
	@Transient
	public Product getProduct(){
		AICacheManager aiCacheManager = AICacheManager.getInstance();
		Map<Integer,List<Product>> m_product = aiCacheManager.getMap(GlobalConstant.CACHE_PRODUCT_MAP);
		List<Product> products = m_product.get(GlobalConstant.OPER_ID_ALL);
		for (Product product : products) {
			if(StringUtils.equals(this.productId, product.getProductId())){
				return product;
			} 
        }
		return null;
	}
}
